Hello World!


Traditionally, all programming language tutorials start with the "Hello World!" program. Its only function is to print "Hello World!" on the screen, and it is used to demonstrate the general look and feel of the language, as well as basic features which must be present. In fact, a web site called the Hello World Page contains the "Hello World!" programs to hundreds of languages.

So, let's get right to the chase. To write programs in Salsa, you can use any word processor you like, as long as you always save your documents in plain ASCII format. Some processors, like SimpleText on the Mac, edit in DOS, Write in Windows, or any of the UNIX text editors always save in plain ASCII format, so these are good choices for editors. Make a document called "hello" in your Salsa directory, and put this text in it:
def main()
{
	println("Hello World!");
}

Now save it and run Salsa -- on a Mac, double-click on the Salsa icon, in DOS or UNIX, type s. When the "> " appears (this is called the command line), type "exec hello". This tells Salsa to compile your code, and then run it. The result should be the words "Hello World!" appearing on the screen, and then the command line reappearing to indicate that the program is done, and Salsa is awaiting your next command. To quit Salsa, type "exit" at the command line.

Note for DOS or UNIX users:
You can give Salsa commands from the DOS prompt or the UNIX shell prompt. It will execute that command, and then exit. For example, to run the hello program as we just did, you could type "s exec hello" from DOS or a UNIX shell, and the same thing would happen, without the initial header. This is a quick way to execute one command, although for multiple commands and other features you may find it more useful to actually enter the program as before.

So let's take a look at this simple program. The first line starts with "def". This indicates that the following will be a function. Then the name of the function, "main", follows. After that, there is an empty set of parenthesis. If we wanted to give main any parameters, we could list them here. The piece of code we have documented so far is called the function header because it heads the function we want to define. Unlike most procedural languages, Salsa is not typed, which means you do not have to declare variables or functions before you use them. That is why we do not have to specify what kind of value main will return -- it could return anything, including nothing. Also, we could declare main anywhere in our program, no matter who calls it. This removes a lot of hassle from the programmer, since he needs no function prototyping or header file inclusion.

After the function header, a pair of braces indicate where the body of the function begins and ends. The only statement we have prints "Hello World!" on the screen. Notice that it ends with a semi-colon. Every statement in Salsa ends with a semi-colon. In our statement, the function println is called with a string parameter. This string is, of course, the text to be printed. println prints the arguments given followed by a return carrage. If you typed "println("Hello ","World!");", it would have the same effect.

Many questions that immediately arise include "Can I space things differently?", "Can I use different capitalization?", and "What if I don't use a semi-colon?" First, Salsa is not case-sensitive, so you could type "PrintLn" or even "pRInTlN" and it would all be equivelent. Second, you can add whitespace (spaces, tabs, returns, line feeds, etc.) whereever you want, except in the middle of indentifiers (i.e. you can't use "pri ntln" when you mean "println". As for the semi-colon, the golden rule is the same as in C: always put a semi-colon after every line, except never after a set of braces.

The next session in the Salsa Tutorial discusses variables and operators.
Web page maintained by Jason Cohen